home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
526-550
/
disk_527
/
toolmanager
/
source
/
editwindow.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
19KB
|
574 lines
/*
* editwindow.c V1.4
*
* edit window
*
* (c) 1991 by Stefan Becker
*
*/
#include "ToolManager.h"
/* Structures for window */
extern char WBScreenName[];
static char WindowTitle[]="Edit Tool Definition"; /* Window title */
extern struct NewWindow nw;
static struct Window *w;
static struct MsgPort *wp;
static ULONG wh; /* Window height */
static struct Screen *pubsc; /* Workbench screen */
/* Structures for window gadgets */
static void *vi; /* Visual information is a *PRIVATE* data field! */
static struct TextAttr ta={"topaz.font",8,0,0};
static struct Gadget *gl; /* Gadget list */
#define TOGAD_ID 1
static char ToolGadgetText[]="Type ";
static char *ToolLabelTexts[]={"Dummy","CLI","WB",NULL};
#define ALGAD_ID 2
extern char AliasKey[];
static struct Gadget *alsg;
#define RNGAD_ID 3
extern char RealKey[];
static struct Gadget *rnsg;
#define WDGAD_ID 4
extern char DirKey[];
static struct Gadget *wdsg;
#define STGAD_ID 5
extern char StackKey[];
static struct Gadget *stig;
#define HKGAD_ID 6
extern char HotKKey[];
static struct Gadget *hksg;
#define MNGAD_ID 7
static char MenuLabelText[]="Menu";
static struct Gadget *mncg;
#define ICGAD_ID 8
static struct Gadget *iccg;
#define ARGAD_ID 9
static char ArgsLabelText[]="Args";
static struct Gadget *arcg;
#define ITGAD_ID 10
extern char ITypeKey[];
extern char BrushKey[];
extern char DObjKey[];
static char *IconLabelTexts[]={BrushKey,DObjKey,NULL};
static struct Gadget *itcg;
#define IFGAD_ID 11
extern char IFileKey[];
static struct Gadget *ifsg;
#define IXGAD_ID 12
static char IconXLabelText[]="X Coord.";
static struct Gadget *ixig;
#define IYGAD_ID 13
static char IconYLabelText[]="Y Coord.";
static struct Gadget *iyig;
#define OKGAD_ID 14
static char OKButtonText[]="OK";
#define CAGAD_ID 15
static char CancelButtonText[]="Cancel";
static struct Gadget *curg; /* Current active string gadget */
/* miscellaneous */
extern WORD lvord;
static struct ToolNode *etn; /* Pointer to edit tool node */
static struct ConfigBlock *cb; /* Pointer to config block */
/* Create config block */
static BOOL GetConfigBlock(struct ToolNode *tn)
{
if (!(cb=malloc(sizeof(struct ConfigBlock)))) return(FALSE);
/* Init config block */
InitConfigBlock(cb);
/* Copy tools parameters */
cb->cb_Type=tn->tn_Type;
cb->cb_Flags=tn->tn_Flags;
cb->cb_Stack=tn->tn_Stack;
strcpy(cb->cb_Alias,tn->tn_Node.ln_Name);
if (tn->tn_RealName) strcpy(cb->cb_RealName,tn->tn_RealName);
if (tn->tn_WorkDir) strcpy(cb->cb_WorkDir,tn->tn_WorkDir);
if (tn->tn_HotKey) strcpy(cb->cb_HotKey,tn->tn_HotKey);
if (tn->tn_IconFile) strcpy(cb->cb_IconFile,tn->tn_IconFile);
if (tn->tn_Icon)
{
cb->cb_IconX=tn->tn_Icon->do_CurrentX;
cb->cb_IconY=tn->tn_Icon->do_CurrentY;
}
/* All OK */
return(TRUE);
}
/* Create gadgets */
static BOOL CreateGadgets(ULONG width)
{
struct NewGadget ng;
struct Gadget *g;
struct TextFont *f;
UWORD topborder,leftedge,fheight;
UWORD fwidth,wg;
BOOL dummy=cb->cb_Type==TNTYPE_DUMMY;
BOOL nicon=dummy || !(cb->cb_Flags&TNFLAGS_ICON);
char buf[BUFLEN];
if (!(f=OpenFont(pubsc->Font))) goto cge1; /* Open window font */
topborder=pubsc->WBorTop+f->tf_YSize+1; /* Top border offset */
CloseFont(f); /* Close font */
if (!(f=OpenFont(&ta))) goto cge1; /* Open window font */
fheight=f->tf_YSize+INTERHEIGHT; /* font height */
fwidth=f->tf_XSize; /* font width */
CloseFont(f); /* Close font */
/* Create gadget list */
gl=NULL;
g=CreateContext(&gl);
/* Calculate window values */
leftedge=8*fwidth+pubsc->WBorLeft+2*INTERWIDTH;
/* 1. gadget: Cycle, Dummy tool */
ng.ng_LeftEdge=leftedge;
ng.ng_TopEdge=topborder+INTERHEIGHT;
ng.ng_Width=5*fwidth+WDRAGBARLEN;
ng.ng_Height=fheight;
ng.ng_GadgetText=ToolGadgetText;
ng.ng_TextAttr=&ta;
ng.ng_GadgetID=TOGAD_ID;
ng.ng_Flags=PLACETEXT_LEFT;
ng.ng_VisualInfo=vi;
ng.ng_UserData=NULL;
if (!(g=CreateGadget(CYCLE_KIND,g,&ng,
GTCY_Labels,ToolLabelTexts,
GTCY_Active,cb->cb_Type,
TAG_DONE)))
goto cge2;
/* 2. gadget: String, Alias */
ng.ng_TopEdge+=g->Height+INTERHEIGHT;
ng.ng_Width=width-leftedge+2*INTERWIDTH;
ng.ng_Height=fheight+2;
ng.ng_GadgetText=AliasKey;
ng.ng_GadgetID=ALGAD_ID;
if (!(alsg=g=CreateGadget(STRING_KIND,g,&ng,
GTST_String,cb->cb_Alias,
GTST_MaxChars,BUFLEN-1,
TAG_DONE)))
goto cge2;
/* 3. gadget: String, RealName */
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_GadgetText=RealKey;
ng.ng_GadgetID=RNGAD_ID;
if (!(rnsg=g=CreateGadget(STRING_KIND,g,&ng,
GTST_String,cb->cb_RealName,
GTST_MaxChars,BUFLEN-1,
GA_Disabled,dummy,
TAG_DONE)))
goto cge2;
/* 4. gadget: String, WorkDir */
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_GadgetText=DirKey;
ng.ng_GadgetID=WDGAD_ID;
if (!(wdsg=g=CreateGadget(STRING_KIND,g,&ng,
GTST_String,cb->cb_WorkDir,
GTST_MaxChars,BUFLEN-1,
GA_Disabled,dummy,
TAG_DONE)))
goto cge2;
/* 5. gadget: Integer, Stack */
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_GadgetText=StackKey;
ng.ng_GadgetID=STGAD_ID;
if (!(stig=g=CreateGadget(INTEGER_KIND,g,&ng,
GTIN_Number,cb->cb_Stack,
GA_Disabled,dummy,
TAG_DONE)))
goto cge2;
/* 6. gadget: String, HotKey */
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_GadgetText=HotKKey;
ng.ng_GadgetID=HKGAD_ID;
if (!(hksg=g=CreateGadget(STRING_KIND,g,&ng,
GTST_String,cb->cb_HotKey,
GTST_MaxChars,BUFLEN-1,
GA_Disabled,dummy,
TAG_DONE)))
goto cge2;
/* 7. gadget: CheckBox, Menu */
wg=4*fwidth+2*INTERWIDTH;
ng.ng_LeftEdge=wg+pubsc->WBorLeft;
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_Width=10;
ng.ng_Height=fheight;
ng.ng_GadgetText=MenuLabelText;
ng.ng_GadgetID=MNGAD_ID;
if (!(mncg=g=CreateGadget(CHECKBOX_KIND,g,&ng,
GTCB_Checked,cb->cb_Flags&TNFLAGS_MENU,
TAG_DONE)))
goto cge2;
/* 8. gadget: CheckBox, Icon */
ng.ng_LeftEdge+=g->Width+wg;
ng.ng_GadgetText=DObjKey;
ng.ng_GadgetID=ICGAD_ID;
if (!(iccg=g=CreateGadget(CHECKBOX_KIND,g,&ng,
GTCB_Checked,cb->cb_Flags&TNFLAGS_ICON,
GA_Disabled,dummy,
TAG_DONE)))
goto cge2;
/* 9. gadget: CheckBox, Args */
ng.ng_LeftEdge+=g->Width+wg;
ng.ng_GadgetText=ArgsLabelText;
ng.ng_GadgetID=ARGAD_ID;
if (!(arcg=g=CreateGadget(CHECKBOX_KIND,g,&ng,
GTCB_Checked,!(cb->cb_Flags&TNFLAGS_NARG),
GA_Disabled,dummy,
TAG_DONE)))
goto cge2;
/* 10. gadget: Cycle, Icon type */
ng.ng_LeftEdge=leftedge;
ng.ng_TopEdge+=g->Height+INTERHEIGHT;
ng.ng_Width=5*fwidth+WDRAGBARLEN;
ng.ng_GadgetText=ITypeKey;
ng.ng_GadgetID=ITGAD_ID;
if (!(itcg=g=CreateGadget(CYCLE_KIND,g,&ng,
GTCY_Labels,IconLabelTexts,
GTCY_Active,(cb->cb_Flags&TNFLAGS_DOBJ)?1:0,
GA_Disabled,nicon,
TAG_DONE)))
goto cge2;
/* 11. gadget: String, IconFile */
ng.ng_TopEdge+=g->Height+INTERHEIGHT;
ng.ng_Width=width-leftedge+2*INTERWIDTH;
ng.ng_Height=fheight+2;
ng.ng_GadgetText=IFileKey;
ng.ng_GadgetID=IFGAD_ID;
if (!(ifsg=g=CreateGadget(STRING_KIND,g,&ng,
GTST_String,cb->cb_IconFile,
GTST_MaxChars,BUFLEN-1,
GA_Disabled,nicon,
TAG_DONE)))
goto cge2;
/* 12. gadget: Integer, Icon X Position */
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_GadgetText=IconXLabelText;
ng.ng_GadgetID=IXGAD_ID;
if (!(ixig=g=CreateGadget(INTEGER_KIND,g,&ng,
GTIN_Number,cb->cb_IconX,
GA_Disabled,nicon,
TAG_DONE)))
goto cge2;
/* 13. gadget: Integer, Icon Y Position */
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_GadgetText=IconYLabelText;
ng.ng_GadgetID=IYGAD_ID;
if (!(iyig=g=CreateGadget(INTEGER_KIND,g,&ng,
GTIN_Number,cb->cb_IconY,
GA_Disabled,nicon,
TAG_DONE)))
goto cge2;
/* 14. gadget: Button, OK */
wg=6*fwidth+INTERWIDTH;
ng.ng_LeftEdge=pubsc->WBorLeft+INTERWIDTH;
ng.ng_TopEdge+=g->Height+2*INTERHEIGHT;
ng.ng_Width=wg;
ng.ng_GadgetText=OKButtonText;
ng.ng_GadgetID=OKGAD_ID;
ng.ng_Flags=PLACETEXT_IN;
if (!(g=CreateGadget(BUTTON_KIND,g,&ng,TAG_DONE))) goto cge2;
/* 15. gadget: Button, Cancel */
ng.ng_LeftEdge=pubsc->WBorLeft+width-wg+INTERWIDTH;
ng.ng_GadgetText=CancelButtonText;
ng.ng_GadgetID=CAGAD_ID;
if (!(g=CreateGadget(BUTTON_KIND,g,&ng,TAG_DONE))) goto cge2;
/* Calculate window height */
wh=ng.ng_TopEdge+g->Height-topborder+INTERHEIGHT;
CloseFont(f);
return(TRUE);
cge2: FreeGadgets(gl);
cge1: return(FALSE);
}
/* Set current string gadget and activate it */
static void SetAndActivateSG(struct Gadget *g)
{
ActivateGadget(g,w,NULL);
curg=g;
}
/* Open edit window */
void OpenEditWindow(ULONG left, ULONG top, ULONG width, struct ToolNode *tn)
{
if (!(pubsc=LockPubScreen(WBScreenName))) /* Lock Workbench screen */
goto oew1;
if (!(vi=GetVisualInfo(pubsc,TAG_DONE))) /* Get visual information */
goto oew2;
if (!GetConfigBlock(tn)) /* Get memory for config block */
goto oew3;
if (!CreateGadgets(width)) /* Create Gadgets */
goto oew4;
/* Open window */
if (!(w=OpenWindowTags(&nw,
WA_Left,left-INTERWIDTH,
WA_Top,top+20,
WA_InnerWidth,width+2*INTERWIDTH,
WA_InnerHeight,wh,
WA_Title,WindowTitle,
WA_PubScreen,pubsc,
WA_AutoAdjust,TRUE,
TAG_DONE)))
goto oew5;
wp=w->UserPort; /* Retrieve window port */
/* Circumvent an intuition.library bug. See AutoDocs for LockPubScreen() */
UnlockPubScreen(NULL,pubsc);
pubsc=NULL;
/* Add gadget list to window */
AddGList(w,gl,(UWORD) -1,(UWORD) -1,NULL);
RefreshGList(gl,w,NULL,(UWORD) -1);
GT_RefreshWindow(w,NULL);
SetAndActivateSG(alsg);
/* Window open! */
etn=tn;
editwinsig=1L<<wp->mp_SigBit;
return;
/* Something went wrong.... */
oew5: FreeGadgets(gl);
oew4: free(cb);
oew3: FreeVisualInfo(vi);
oew2: if (pubsc) UnlockPubScreen(NULL,pubsc);
oew1: return;
}
/* Close edit window */
void CloseEditWindow(void)
{
if (editwinsig)
{
CloseWindow(w);
FreeGadgets(gl);
free(cb);
FreeVisualInfo(vi);
editwinsig=0;
}
}
/* Handle edit window events */
void HandleEditWinEvent(void)
{
BOOL clwin=FALSE; /* TRUE if window should be closed */
struct IntuiMessage *msg;
while ((msg=GT_GetIMsg(wp)) /* && !clwin */)
{
switch (msg->Class)
{
case CLOSEWINDOW: /* User clicked the close gadget */
clwin=TRUE; /* Yes, close window */
break;
case REFRESHWINDOW: /* Window must be refreshed */
GT_BeginRefresh(w);
GT_EndRefresh(w,TRUE);
break;
case GADGETUP: /* User released the gadget */
switch(((struct Gadget *) msg->IAddress)->GadgetID)
{
case TOGAD_ID: /* User selected the Type gadget */
BOOL dummy,nicon;
/* Set type and status flags */
cb->cb_Type=msg->Code;
dummy=cb->cb_Type==TNTYPE_DUMMY; /* DUMMY tool */
nicon=dummy || !(cb->cb_Flags&TNFLAGS_ICON); /* No icon */
/* (de)activate all other gadgets according to the tool type */
GT_SetGadgetAttrs(rnsg,w,NULL,GA_Disabled,dummy,TAG_DONE);
GT_SetGadgetAttrs(wdsg,w,NULL,GA_Disabled,dummy,TAG_DONE);
GT_SetGadgetAttrs(stig,w,NULL,GA_Disabled,dummy,TAG_DONE);
GT_SetGadgetAttrs(hksg,w,NULL,GA_Disabled,dummy,TAG_DONE);
GT_SetGadgetAttrs(iccg,w,NULL,GA_Disabled,dummy,TAG_DONE);
GT_SetGadgetAttrs(arcg,w,NULL,GA_Disabled,dummy,TAG_DONE);
GT_SetGadgetAttrs(itcg,w,NULL,GA_Disabled,nicon,TAG_DONE);
GT_SetGadgetAttrs(ifsg,w,NULL,GA_Disabled,nicon,TAG_DONE);
GT_SetGadgetAttrs(ixig,w,NULL,GA_Disabled,nicon,TAG_DONE);
GT_SetGadgetAttrs(iyig,w,NULL,GA_Disabled,nicon,TAG_DONE);
/* DUMMY tool? Yes -> Set standard values */
if (dummy)
{
GT_SetGadgetAttrs(mncg,w,NULL,GTCB_Checked,TRUE,TAG_DONE);
cb->cb_Flags|=TNFLAGS_MENU; /* Don't discard icon flag yet */
/* Next active gadget */
SetAndActivateSG(alsg);
}
else
ActivateGadget(curg,w,NULL); /* Reactivate old string gadget */
break;
case ALGAD_ID: /* User pressed <return> on Alias gadget */
if (cb->cb_Type==TNTYPE_DUMMY) /* Activate next gadget */
SetAndActivateSG(alsg);
else
SetAndActivateSG(rnsg);
break;
case RNGAD_ID: /* User pressed <return> on RealName gadget */
SetAndActivateSG(wdsg); /* Activate next gadget */
break;
case WDGAD_ID: /* User pressed <return> on WorkDir gadget */
SetAndActivateSG(stig); /* Activate next gadget */
break;
case STGAD_ID: /* User pressed <return> on Stack gadget */
SetAndActivateSG(hksg); /* Activate next gadget */
break;
case HKGAD_ID: /* User pressed <return> on HotKey gadget */
if (cb->cb_Flags&TNFLAGS_ICON) /* Activate next gadget */
SetAndActivateSG(ifsg);
else
SetAndActivateSG(alsg);
break;
case MNGAD_ID: /* User selected the Menu gadget */
cb->cb_Flags^=TNFLAGS_MENU; /* Toggle menu flag */
ActivateGadget(curg,w,NULL); /* Reactivate old string gadget */
break;
case ICGAD_ID: /* User selected the Icon gadget */
BOOL nicon=!(iccg->Flags&SELECTED); /* No icon */
cb->cb_Flags^=TNFLAGS_ICON; /* Toggle icon flag */
/* (de)activate icon parameter gadets according to icon flag state */
GT_SetGadgetAttrs(itcg,w,NULL,GA_Disabled,nicon,TAG_DONE);
GT_SetGadgetAttrs(ifsg,w,NULL,GA_Disabled,nicon,TAG_DONE);
GT_SetGadgetAttrs(ixig,w,NULL,GA_Disabled,nicon,TAG_DONE);
GT_SetGadgetAttrs(iyig,w,NULL,GA_Disabled,nicon,TAG_DONE);
/* Activate next gadget */
if (nicon)
SetAndActivateSG(alsg);
else
ActivateGadget(curg,w,NULL);
break;
case ARGAD_ID: /* User selected the Args gadget */
cb->cb_Flags^=TNFLAGS_NARG; /* Toggle Args flag */
ActivateGadget(curg,w,NULL); /* Reactivate old string gadget */
break;
case ITGAD_ID: /* User selected the IconType gadget */
cb->cb_Flags^=TNFLAGS_DOBJ; /* Toggle icon type flag */
ActivateGadget(curg,w,NULL); /* Reactivate old string gadget */
break;
case IFGAD_ID: /* User pressed <return> on IconFile gadget */
SetAndActivateSG(ixig); /* Activate next gadget */
break;
case IXGAD_ID: /* User pressed <return> on X Coord. gadget */
SetAndActivateSG(iyig); /* Activate next gadget */
break;
case IYGAD_ID: /* User pressed <return> on Y Coord. gadget */
SetAndActivateSG(alsg); /* Activate next gadget */
break;
case OKGAD_ID: /* User selected the OK gadget */
UBYTE oldflags;
/* Window in closing state? Yes --> Skip this event */
if (clwin) break;
/* Copy new tool parameters */
strcpy(cb->cb_Alias,
((struct StringInfo *) alsg->SpecialInfo)->Buffer);
strcpy(cb->cb_RealName,
((struct StringInfo *) rnsg->SpecialInfo)->Buffer);
strcpy(cb->cb_WorkDir,
((struct StringInfo *) wdsg->SpecialInfo)->Buffer);
cb->cb_Stack=((struct StringInfo *) stig->SpecialInfo)->LongInt;
strcpy(cb->cb_HotKey,
((struct StringInfo *) hksg->SpecialInfo)->Buffer);
strcpy(cb->cb_IconFile,
((struct StringInfo *) ifsg->SpecialInfo)->Buffer);
cb->cb_IconX=((struct StringInfo *) ixig->SpecialInfo)->LongInt;
cb->cb_IconY=((struct StringInfo *) iyig->SpecialInfo)->LongInt;
DetachToolList(); /* Tool list will be changed */
/* If the user hasn't changed it's position, the new icon will not
appear at the choosen position if the old one is still there. */
if (etn->tn_AppIcon)
{
RemoveAppIcon(etn->tn_AppIcon);
etn->tn_AppIcon=NULL;
}
/* If the user has changed the tool type to DUMMY, we forget the
previous state of the icon flag for real now */
oldflags=cb->cb_Flags;
if (cb->cb_Type==TNTYPE_DUMMY)
cb->cb_Flags=TNFLAGS_MENU|TNFLAGS_DOBJ;
/* Build new ToolNode */
if (AddToolNode(cb,etn->tn_DirLock))
{
/* New ToolNode was added at the end of list */
struct ToolNode *tn=RemTail(&ToolList); /* Remove new node */
/* Insert it after the old node */
Insert(&ToolList,(struct Node *) tn,(struct Node *) etn);
RemToolNode(etn); /* Remove old node */
/* Now the new node has moved to same place in the list which was
occupied by the old one. Therefore it appears in the same place in
the config file. (But don't forget to save the new definition :-)
The same should be done for the AppMenuItem, but there is no
easy way to do this now... */
clwin=TRUE; /* Close window */
}
else /* No new ToolNode created --> reactivate Alias gadget */
{
/* Restore old flags */
cb->cb_Flags=oldflags;
/* Let the old icon re-appear */
if (etn->tn_Flags&TNFLAGS_ICON)
etn->tn_AppIcon=AddAppIcon((ULONG) etn,NULL,etn->tn_Node.ln_Name,
MyMP,NULL,etn->tn_Icon,TAG_DONE);
/* Beep the user and reactivate old string gadget */
DisplayBeep(NULL);
ActivateGadget(curg,w,NULL);
}
AttachToolList(); /* Tool list has changed */
break;
case CAGAD_ID: /* User selected the cancel gadget */
clwin=TRUE; /* Close window */
break;
}
break;
}
GT_ReplyIMsg(msg);
}
if (clwin) CloseEditWindow();
}